<?php
	class hotelDetailClass {
		protected $param = array(
								"apiKey" => null,
								"cid" => null,
								"locale" => null,
								"currencyCode" => null,
								"hotelId" => null						
							);
							
		protected $wsdl = "http://api.ean.com/ean-services/ws/hotel/v3?wsdl&apiKey=t9grpd33pwudkegxpdrq6xp5";
		protected $objClient;
		protected $xmlParam;
		protected $soapvar;
		protected $objResponse;
		protected $response;
		protected $hotelDetail;
		protected $globalResult = array();
		
		protected function setXmlparam(){	
			$this->xmlParam = '<v3:getInformation>
								 <HotelInformationRequest>
									<apiKey>'.$this->param['apiKey'].'</apiKey>
									<cid>'.$this->param['cid'].'</cid>
									<minorRev>9</minorRev> 
									<customerIpAddress></customerIpAddress>
									<customerSessionId></customerSessionId>
									<customerUserAgent></customerUserAgent>
									<locale>'.$this->param['locale'].'</locale>
									<currencyCode>'.$this->param['currencyCode'].'</currencyCode>
									<hotelId>'.$this->param['hotelId'].'</hotelId> 
								 </HotelInformationRequest>
							  </v3:getInformation>';
		}
		
		protected function getdataParam(){
			$this->objClient = new SoapClient($this->wsdl, array('trace' => true,'exceptions' => 0,'features'=>SOAP_SINGLE_ELEMENT_ARRAYS, 'encoding' => 'UTF-8'));
			$this->setXmlparam();
			$this->soapvar = new SoapVar($this->xmlParam, XSD_ANYXML);
			$this->objResponse = $this->objClient->__soapCall("getInformation", array($this->soapvar));
		}
	
		protected function setSimpleXml(){
			$this->response = $this->objClient->__getLastResponse();
			$xml = simplexml_load_string($this->response, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
			$xml->registerXPathNamespace('soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
			$xml->registerXPathNamespace('ns1', 'http://v3.hotel.wsapi.ean.com/');
			$result = $xml->xpath('//ns1:getInformationResponse');
			$result = $result[0]->HotelInformationResponse;
			$this->hotelDetail = $result;
		}
		
		public function setParam($apiKey, $cid, $locale, $currencyCode,$hotelId){
			$this->param = array(
								"apiKey" => $apiKey,
								"cid" => $cid,
								"locale" => $locale,
								"currencyCode" => $currencyCode,
								"hotelId" => $hotelId								
							);
					
			$this->getdataParam();
			$this->setSimpleXml();
		}
		
		public function getHotelDetail(){
			$details = $this->hotelDetail;
			
			$roomTypes = array();
			foreach($details->RoomTypes->RoomType as $rooms){
				
				$roomAmenities = array();
				foreach($rooms->roomAmenities->RoomAmenity as $roomAmenity){
					$roomAmenities[] = (object) array(
									"amenityId" => (string) $roomAmenity['amenityId'],
									"amenity" => (string) $roomAmenity->amenity
					);
				}
				
				$roomTypes[] = (object) array(
								"roomCode" => (string) $rooms['roomCode'],
								"roomTypeId" => (string) $rooms['roomTypeId'],
								"description" => (string) $rooms->description,
								"descriptionLong" => (string) $rooms->descriptionLong,
								"descriptionLong" => (string) $rooms->descriptionLong,
								"roomAmenities" => $roomAmenities
				);
			}
			
			$propertyAmenities = array();
			foreach($details->PropertyAmenities->PropertyAmenity as $property){
				$propertyAmenities[] = (object) array(
								"amenityId" => (string) $property->amenityId,
								"amenity" => (string) $property->amenity
				);
			}
			
			$hotelImages = array();
			foreach($details->HotelImages->HotelImage as $image){
				$hotelImages[] = (object) array(
								"hotelImageId" => (string) $image->hotelImageId,
								"hotelImageUrl" => (string) $image->url,
								"hotelImageThumbnailUrl" => (string) $image->thumbnailUrl,
								"supplierId" => (string) $image->supplierId
				);
			}
			
			$this->globalResult[] = (object) array(
						"customerSessionId" => (string) $details->customerSessionId,
						"hotelId" => (string) $details->HotelSummary->hotelId,
						"hotelName" => (string) $details->HotelSummary->name,
						"hotelAddress" => (string) $details->HotelSummary->address1,
						"hotelCity" => (string) $details->HotelSummary->city,
						"hotelPostalCode" => (string) $details->HotelSummary->postalCode,
						"hotelCountryCode" => (string) $details->HotelSummary->countryCode,
						"hotelPropertyCategory" => (string) $details->HotelSummary->propertyCategory,
						"hotelRating" => (string) $details->HotelSummary->hotelRating,
						"hotelTripAdvisorRating" => (string) $details->HotelSummary->tripAdvisorRating,
						"hotelLocationDescription" => (string) $details->HotelSummary->locationDescription,
						"hotelHighRate" => (string) $details->HotelSummary->highRate,
						"hotelLowRate" => (string) $details->HotelSummary->lowRate,
						"hotelLatitude" => (string) $details->HotelSummary->latitude,
						"hotelLongitude" => (string) $details->HotelSummary->longitude,
						"hotelNumberOfRooms" => (string) $details->HotelDetails->numberOfRooms,
						"hotelNumberOfFloors" => (string) $details->HotelDetails->numberOfFloors,
						"hotelCheckInTime" => (string) $details->HotelDetails->checkInTime,
						"hotelCheckOutTime" => (string) $details->HotelDetails->checkOutTime,
						"hotelPropertyInformation" => (string) $details->HotelDetails->propertyInformation,
						"hotelAreaInformation" => (string) $details->HotelDetails->areaInformation,
						"hotelPropertyDescription" => (string) $details->HotelDetails->propertyDescription,
						"hotelPolicy" => (string) $details->HotelDetails->hotelPolicy,
						"hotelRoomInformation" => (string) $details->HotelDetails->roomInformation,
						"hotelDrivingDirections" => (string) $details->HotelDetails->drivingDirections,
						"hotelCheckInInstructions" => (string) $details->HotelDetails->checkInInstructions,
						"hotelRoomTypes" => $roomTypes,
						"hotelPropertyAmenities" => $propertyAmenities,
						"hotelImages" => $hotelImages
			);
			
			return 	$this->globalResult;
		}
	}
	
	//$hotels = new hotelDetailClass();
	//$hotels->setParam("t9grpd33pwudkegxpdrq6xp5","55505","en_US","USD","106347");
	//$hotels = $hotels->getHotelDetail();
?>
<!--<pre><?php // print_r($hotels); ?></pre>-->